package com.soilflow.know.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.soilflow.common.domain.KnowsReport;
import com.soilflow.common.domain.dto.KnowsReportDto;
import com.soilflow.common.domain.vo.KnowsReportVo;
import com.soilflow.know.mapper.KnowsReportMapper;
import com.soilflow.know.service.KnowsReportService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class KnowsReportServiceImpl extends ServiceImpl<KnowsReportMapper, KnowsReport> implements KnowsReportService {

    @Resource
    private KnowsReportMapper reportMapper;


    @Override
    public List<KnowsReportVo> reportList(KnowsReportDto dto) {
        return reportMapper.reportList(dto);
    }

    @Override
    public void addReport(KnowsReportDto dto) {
        KnowsReport knowsReport = new KnowsReport();
        BeanUtils.copyProperties(dto,knowsReport);
        reportMapper.insert(knowsReport);
    }

    @Override
    public void updateReport(KnowsReportDto dto) {
        KnowsReport knowsReport = new KnowsReport();
        BeanUtils.copyProperties(dto,knowsReport);
        knowsReport.setId(dto.getId());
        reportMapper.updateById(knowsReport);
    }

    @Override
    public KnowsReportVo getReportById(Long id) {
        KnowsReportVo vo = new KnowsReportVo();
        KnowsReport knowsReport = reportMapper.selectById(id);
        BeanUtils.copyProperties(knowsReport,vo);
        return vo;
    }
}
